package com.abbas.smartCity.ui.findJob;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.widget.LinearLayoutCompat;

import com.abbas.smartCity.App;
import com.abbas.smartCity.Death;
import com.abbas.smartCity.R;
import com.abbas.smartCity.base.BaseFragment;
import com.abbas.smartCity.bean.UserInfoBean;
import com.abbas.smartCity.bean.findJob.ProfessionList;
import com.abbas.smartCity.bean.findJob.QueryResume;
import com.abbas.smartCity.retroft.ICallback;
import com.google.gson.Gson;

import java.util.List;

import retrofit2.Call;


public class MineFragment extends BaseFragment {

    private ImageView im;
    private TextView tag1;
    private TextView tag2;
    private TextView tag3;
    private TextView tag4;
    private TextView tag5;
    private TextView tag6;
    private LinearLayoutCompat qiuzhiInfo;
    private EditText workingExp;
    private EditText mostEdu;
    private EditText adress;
    private TextView wantProf;
    private EditText wantMoney;
    private EditText mineDescription;
    private EditText EduHistory;
    private EditText workingHistory;
    private Button change;
    private QueryResume.DataBean resumeData;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine2;
    }

    @Override
    protected void initView() {
        im = (ImageView) rootView.findViewById(R.id.im);
        tag1 = (TextView) rootView.findViewById(R.id.tag1);
        tag2 = (TextView) rootView.findViewById(R.id.tag2);
        tag3 = (TextView) rootView.findViewById(R.id.tag3);
        tag4 = (TextView) rootView.findViewById(R.id.tag4);
        tag5 = (TextView) rootView.findViewById(R.id.tag5);
        tag6 = (TextView) rootView.findViewById(R.id.tag6);
        qiuzhiInfo = (LinearLayoutCompat) rootView.findViewById(R.id.qiuzhiInfo);
        workingExp = (EditText) rootView.findViewById(R.id.working_exp);
        mostEdu = (EditText) rootView.findViewById(R.id.most_edu);
        adress = (EditText) rootView.findViewById(R.id.adress);
        wantProf = (TextView) rootView.findViewById(R.id.want_prof);
        wantMoney = (EditText) rootView.findViewById(R.id.want_money);
        mineDescription = (EditText) rootView.findViewById(R.id.mineDescription);
        EduHistory = (EditText) rootView.findViewById(R.id.EduHistory);
        workingHistory = (EditText) rootView.findViewById(R.id.workingHistory);
        change = (Button) rootView.findViewById(R.id.change);

    }

    @Override
    protected void initData() {
        final UserInfoBean.UserBean user = App.getUser();
        final List<ProfessionList.RowsBean> professionListRows = Death.professionList.getRows();

        tag1.setText(user.getNickName());
        tag2.setText(user.getEmail());
        tag3.setText(user.getPhonenumber());
        tag4.setText(user.getSex().equals("0") ? "男" : "女");
        tag5.setText(String.valueOf(user.getUserId()));

        api.getResume(user.getUserId()).enqueue(new ICallback<QueryResume>() {
            @Override
            public void onSuccess(Call<QueryResume> call, QueryResume resumeData) {
                if (resumeData != null) {
                    change.setText("修改简历");
                    qiuzhiInfo.setVisibility(View.VISIBLE);

                    final QueryResume.DataBean data = resumeData.getData();
                    workingExp.setText(data.getExperience());
                    mostEdu.setText(data.getMostEducation());
                    adress.setText(data.getAddress());
                    wantMoney.setText(data.getMoney());
                    wantProf.setText(null == data.getPositionName() ? "暂无" : data.getPositionName().toString());
                    mineDescription.setText(data.getIndividualResume());
                    EduHistory.setText(data.getEducation());
                    workingHistory.setText(data.getExperience());
                } else {
                    change.setText("暂无简历，点击新增简历");
                }
            }
        });
    }

    @Override
    protected void initEvent() {
        change.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (resumeData == null) {
                    startActivity(AddResumeActivity.class);
                } else {
                    final Intent intent = new Intent(getContext(), AddResumeActivity.class);
                    intent.putExtra("type", 0);
                    intent.putExtra("data", new Gson().toJson(resumeData));
                    startActivity(intent);
                }
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }
}